# -*- coding: utf-8 -*-
"""
@Time ： 2023/5/13 0013 19:13
@Auth ： ysc
@File ：PipelinePage.py
@IDE ：PyCharm
"""
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from Lib.common_lib import LOG_INFO, LOG_ERROR
import time

from Page.ImageBuildPage import ImageBuild


class PipelinePage(object):
    """流水线页面元素"""

    def __init__(self, driver):
        """
        加载驱动、日志类
        """
        self.driver = driver
        self.repo_url = None
        self.os_name = None
        self.version = None
        self.release = None

        self.os_name_ib = None
        self.kernel_param = None
        self.repo_url_ib = None

    def get_url(self, url):
        """
        进入网址页面
        """
        self.driver.get(url)

    def delete_button(self):
        """流水线删除按钮"""
        try:
            self.driver.find_element(By.XPATH, '//*[@id="box"]/footer/button[3]/span').click()
        except Exception as e:
            message = '流水线删除按钮定位失败'
            LOG_ERROR("error: found delete_button timeout")
            print(e)
            LOG_INFO(message)

    def select_first_pipeline(self):
        """选择流水线列表第一条"""
        try:
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div[1]/div/div[2]/div/div[1]/div['
                                               '3]/div/div[1]/div/table/tbody/tr[1]/td[2]/div/span').click()
        except Exception as e:
            message = '流水线列表第一条元素定位失败'
            LOG_ERROR("error: found delete_button timeout")
            print(e)
            LOG_INFO(message)

    def pipeline_list_button(self):
        """流水线列表按钮"""
        try:
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[1]/div/span[2]/span[1]/span').click()
        except Exception as e:
            message = '流水线列表按钮元素定位失败'
            LOG_ERROR("error: found pipeline_list_btn timeout")
            print(e)
            LOG_INFO(message)

    def version_image_config(self):
        """版本镜像参数设置按钮"""
        try:
            self.driver.find_element(By.XPATH, '//*[@id="left"]/div[3]/div[2]/div[1]').click()
        except Exception as e:
            message = '版本镜像参数设置按钮定位失败'
            LOG_ERROR("error: found version_image_config timeout")
            print(e)
            LOG_INFO(message)

    def version_image_page_info(self):
        """版本镜像参数配置信息"""
        try:
            info_title = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[1]/span')
            info_1 = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[2]/div/div[1]/div[1]/div')
            info_2 = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[2]/div/div[2]/div[1]/div')
            info_3 = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[2]/div/div[3]/div[1]/div')
            info_4 = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[2]/div/div[4]/div[1]/div')
            info_5 = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[2]/div/div[5]/div[1]/div')

            return [info_title.text, info_1.text, info_2.text, info_3.text, info_4.text, info_5.text]
        except Exception as e:
            message = '弹窗校验信息元素定位失败'
            LOG_ERROR("error: found pipeline_info_valid timeout")
            print(e)
            LOG_INFO(message)

    def get_version_image_page_info(self):
        """获取版本镜像参数设置内容"""
        try:
            info_repo = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[2]/div/div[1]/div[2]')
            info_type = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[2]/div/div[2]/div[2]')
            info_name = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[2]/div/div[3]/div[2]')
            info_version = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[2]/div/div[4]/div[2]')
            info_release = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[2]/div/div[5]/div[2]')

            return [info_repo.text, info_type.text, info_name.text, info_version.text, info_release.text]
        except AttributeError as e:
            message = '获取版本镜像参数内容失败'
            LOG_ERROR("error: found pipeline_info_value timeout")
            print(e)
            LOG_INFO(message)

    def version_image_config_change(self):
        """版本镜像参数修改按钮"""
        try:
            self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[1]/button/span').click()
        except Exception as e:
            message = '版本镜像参数修改按钮定位失败'
            LOG_ERROR("error: found pipeline_info_valid timeout")
            print(e)
            LOG_INFO(message)

    def version_image_config_save_button(self):
        """版本镜像参数保存按钮"""
        try:
            self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[1]/div/button[1]/span').click()
        except Exception as e:
            message = '版本镜像参数保存按钮定位失败'
            LOG_ERROR("error: found version_image_config_save_button timeout")
            print(e)
            LOG_INFO(message)

    def version_image_config_cancel_button(self):
        """版本镜像参数取消修改按钮"""
        try:
            self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[1]/div/button[2]/span').click()
        except Exception as e:
            message = '版本镜像参数保存按钮定位失败'
            LOG_ERROR("error: found version_image_config_cancel_button timeout")
            print(e)
            LOG_INFO(message)

    def image_build_enable_check(self):
        """镜像构建按钮使能检查"""
        try:
            image_btn = self.driver.find_element(By.XPATH, '//*[@id="box"]/footer/button[1]')
            clone_btn = self.driver.find_element(By.XPATH, '//*[@id="box"]/footer/button[2]')
            delete_btn = self.driver.find_element(By.XPATH, '//*[@id="box"]/footer/button[3]')

            return [image_btn, clone_btn, delete_btn]
        except Exception as e:
            message = '镜像构建按钮使能检查'
            LOG_ERROR("error: found image_build_enable_check timeout")
            print(e)
            LOG_INFO(message)

    def image_build_button(self):
        """镜像构建按钮"""

    def load_image_repo_url(self):
        """
        版本参数配置——repo源输入框元素
        """
        try:
            self.repo_url = self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div/div['
                                                               '2]/section/section/main/div/div[2]/form/div[1]/div/div['
                                                               '1]/textarea')
        except Exception as e:
            message = 'repo源输入框元素定位失败'
            LOG_ERROR("error: found image_build_enable_check timeout")
            print(e)
            LOG_INFO(message)

    def image_type_list(self):
        """版本参数配置——镜像类型列表"""
        try:
            self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div/div['
                                               '2]/section/section/main/div/div[2]/form/div['
                                               '2]/div/div/div/div/div/input').click()
        except Exception as e:
            message = '镜像类型下拉框元素定位失败'
            LOG_ERROR("error: found image_build_enable_check timeout")
            print(e)
            LOG_INFO(message)

    def switch_image_type(self, image_type="standard"):
        """选择相应的镜像类型"""
        if image_type == "standard":
            try:
                self.driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/div/div[1]/ul/li[1]').click()
            except Exception as e:
                message = 'standard镜像类型定位失败'
                LOG_ERROR("error: found switch_type_standard timeout")
                print(e)
                LOG_INFO(message)
        elif image_type == "everything":
            try:
                self.driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/div/div[1]/ul/li[2]').click()
            except AttributeError as e:
                message = 'everything镜像类型定位失败'
                LOG_ERROR("error: found switch_type_everything timeout")
                print(e)
                LOG_INFO(message)
        elif image_type == "everything_src":
            try:
                self.driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/div/div[1]/ul/li[3]').click()
            except AttributeError as e:
                message = 'everything_src镜像类型定位失败'
                LOG_ERROR("error: found switch_type_everything_src timeout")
                print(e)
                LOG_INFO(message)
        elif image_type == "everything_debug":
            try:
                self.driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/div/div[1]/ul/li[4]').click()
            except AttributeError as e:
                message = 'everything_src镜像类型定位失败'
                LOG_ERROR("error: found switch_type_everything_debug timeout")
                print(e)
                LOG_INFO(message)
        elif image_type == "edge":
            try:
                self.driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/div/div[1]/ul/li[5]').click()
            except AttributeError as e:
                message = 'edge镜像类型定位失败'
                LOG_ERROR("error: found switch_type_edge timeout")
                print(e)
                LOG_INFO(message)
        else:
            try:
                self.driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/div/div[1]/ul/li[6]').click()
            except AttributeError as e:
                message = 'desktop镜像类型定位失败'
                LOG_ERROR("error: found switch_type_desktop timeout")
                print(e)
                LOG_INFO(message)

    def load_image_os_name(self):
        """版本参数配置——产品名称元素"""
        try:
            self.os_name = self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div/div['
                                                              '2]/section/section/main/div/div[2]/form/div[3]/div['
                                                              '1]/div/div[1]/div/input')
        except AttributeError as e:
            message = '产品名称元素定位失败'
            LOG_ERROR("error: found image_os_name timeout")
            print(e)
            LOG_INFO(message)

    def load_image_version_number(self):
        """版本参数配置——版本号元素"""
        try:
            self.version = self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div/div['
                                                              '2]/section/section/main/div/div[2]/form/div[3]/div['
                                                              '2]/div/div[1]/div/input')
        except AttributeError as e:
            message = '版本号元素定位失败'
            LOG_ERROR("error: found image_os_version timeout")
            print(e)
            LOG_INFO(message)

    def load_image_release(self):
        """版本参数配置——release号元素"""
        try:
            self.release = self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div/div['
                                                              '2]/section/section/main/div/div[2]/form/div[3]/div['
                                                              '3]/div/div/div/input')
        except AttributeError as e:
            message = 'release号元素定位失败'
            LOG_ERROR("error: found image_release timeout")
            print(e)
            LOG_INFO(message)

    def version_image_param_set(self, repo_url, os_name, version_num, release):
        """版本参数配置设置"""
        self.repo_url.send_keys(repo_url)
        self.os_name.send_keys(os_name)
        self.version.send_keys(version_num)
        self.release.send_keys(release)

    def version_image_fill_check(self):
        """版本镜像参数必填校验"""
        try:
            info_1_valid = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[2]/form/div[1]/div/div[2]')
            info_2_valid = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[2]/form/div[2]/div/div[2]')
            info_3_valid = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[2]/form/div[3]/div['
                                                              '1]/div/div[2]')
            info_4_valid = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[2]/form/div[3]/div['
                                                              '2]/div/div[2]')

            return [info_1_valid.text, info_2_valid.text, info_3_valid.text, info_4_valid.text]
        except Exception as e:
            message = '版本镜像参数必填报错信息检查'
            LOG_ERROR("error: found version_image_fill_check timeout")
            print(e)
            LOG_INFO(message)

    def version_image_format_valid(self):
        """版本镜像前端格式校验"""
        try:
            info_1_valid = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[2]/form/div[1]/div/div[2]')
            info_2_valid = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[2]/form/div[3]/div['
                                                              '1]/div/div[2]')
            info_3_valid = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[2]/form/div[3]/div['
                                                              '2]/div/div[2]')

            return [info_1_valid.text, info_2_valid.text, info_3_valid.text]
        except Exception as e:
            message = '版本镜像参数格式校验报错信息检查'
            LOG_ERROR("error: found version_image_format_valid timeout")
            print(e)
            LOG_INFO(message)

    def build_system_button(self):
        """构建系统按钮"""
        try:
            self.driver.find_element(By.XPATH, '//*[@id="left"]/div[3]/div[3]/div').click()
        except Exception as e:
            message = '构建系统按钮元素定位检查'
            LOG_ERROR("error: found build_system_button timeout")
            print(e)
            LOG_INFO(message)

    def build_system_info_check(self):
        """构建系统页面信息检查"""
        try:
            info_up_title = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[1]/div/span')
            info_down_title = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[2]/div[1]/p')
            info_1 = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[1]/table/tr[1]/td[1]')
            info_2 = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[1]/table/tr[2]/td[1]')
            info_3 = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[1]/table/tr[3]/td[1]')
            info_4 = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[1]/table/tr[4]/td[1]')

            return [info_up_title.text, info_1.text, info_2.text, info_3.text, info_4.text, info_down_title.text]
        except Exception as e:
            message = '构建系统页面信息检查'
            LOG_ERROR("error: found build_system_info_check timeout")
            print(e)
            LOG_INFO(message)

    def image_status_without_build(self):
        """镜像未构建状态"""
        try:
            status_1 = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[1]/table/tr[1]/td[2]/span')
            status_2 = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[2]/div[2]/div[2]/p')

            return [status_1.text, status_2.text]
        except Exception as e:
            message = '未触发构建时，镜像构建状态'
            LOG_ERROR("error: found image_status_without_build timeout")
            print(e)
            LOG_INFO(message)

    def image_build_his_button(self):
        """镜像构建历史按钮"""
        try:
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[1]/div[2]').click()
        except Exception as e:
            message = "像构建历史按钮定位失败"
            LOG_ERROR("error: found image_status_without_build timeout")
            print(e)
            LOG_INFO(message)

    def image_build_his_info(self):
        try:
            info_title = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div[1]')
            info_1 = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div['
                                                        '2]/div/div[1]/div[2]/table/thead/tr/th[2]/div')
            info_2 = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div['
                                                        '2]/div/div[1]/div[2]/table/thead/tr/th[3]/div')
            info_3 = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div['
                                                        '2]/div/div[1]/div[2]/table/thead/tr/th[4]/div')
            info_4 = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div['
                                                        '2]/div/div[1]/div[2]/table/thead/tr/th[5]/div')
            info_5 = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div['
                                                        '2]/div/div[1]/div[2]/table/thead/tr/th[6]/div')
            info_6 = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div['
                                                        '2]/div/div[1]/div[2]/table/thead/tr/th[7]/div')

            return [info_title.text, info_1.text, info_2.text, info_3.text, info_4.text, info_5.text, info_6.text]
        except Exception as e:
            message = '构建系统页面信息检查'
            LOG_ERROR("error: found build_system_info_check timeout")
            print(e)
            LOG_INFO(message)

    def account_manager_button(self):
        """用户管理页面按钮"""
        try:
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[1]/div[3]').click()
        except Exception as e:
            message = '用户管理页面按钮检查'
            LOG_ERROR("error: found account_manager_button timeout")
            print(e)
            LOG_INFO(message)

    def account_manager_info(self):
        """用户管理页面信息检查"""
        try:
            info_title = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/p')
            info_1 = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div['
                                                        '2]/div/div[1]/div[2]/table/thead/tr/th[1]/div')
            info_2 = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div['
                                                        '2]/div/div[1]/div[2]/table/thead/tr/th[2]/div')
            info_3 = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div['
                                                        '2]/div/div[1]/div[2]/table/thead/tr/th[2]/div')

            return [info_title.text, info_1.text, info_2.text, info_3.text]
        except Exception as e:
            message = '用户管理页面信息检查'
            LOG_ERROR("error: found account_manager_info timeout")
            print(e)
            LOG_INFO(message)

    def add_user_btn(self):
        """添加用户按钮"""
        try:
            self.driver.find_element(By.XPATH,
                                     "//*[@id=\"app\"]/div[1]/div/div[2]/div/div[2]/div/div[1]/button/i").click()
        except Exception as e:
            message = '添加用户按钮检查'
            LOG_ERROR("error: found add_user_btn timeout")
            print(e)
            LOG_INFO(message)

    def add_user_alert_info(self):
        """添加用户弹窗信息检查"""
        try:
            info_title = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div['
                                                            '4]/div/div/header')
            info_1 = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div['
                                                        '4]/div/div/div/form/div[1]/label')
            info_2 = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div['
                                                        '4]/div/div/div/form/div[2]/label')

            return [info_title.text, info_1.text, info_2.text]
        except Exception as e:
            message = '添加用户弹窗信息检查'
            LOG_ERROR("error: found add_user_alert_info timeout")
            print(e)
            LOG_INFO(message)

    def add_user_cancel_btn(self):
        """添加用户弹窗取消按钮"""
        try:
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div['
                                               '4]/div/div/footer/span/button[2]/span').click()
        except Exception as e:
            message = '添加用户弹窗取消按钮检查'
            LOG_ERROR("error: found add_user_cancel_btn timeout")
            print(e)
            LOG_INFO(message)

    def add_user_confirm_btn(self):
        """添加用户弹窗确认按钮"""
        try:
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div['
                                               '4]/div/div/footer/span/button[1]/span').click()
        except Exception as e:
            message = '添加用户弹窗确认按钮检查'
            LOG_ERROR("error: found add_user_confirm_btn timeout")
            print(e)
            LOG_INFO(message)

    def add_user_info_param_fill_check(self):
        """添加用户弹窗参数必填校验"""
        try:
            check_info_1 = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div['
                                                              '4]/div/div/div/form/div[1]/div/div[2]')
            check_info_2 = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div['
                                                              '4]/div/div/div/form/div[2]/div/div[2]')

            return [check_info_1.text, check_info_2.text]
        except Exception as e:
            message = '添加用户弹窗参数必填校验检查'
            LOG_ERROR("error: found add_user_info_param_fill_check timeout")
            print(e)
            LOG_INFO(message)

    def add_user_send_name(self, account_name):
        """添加用户——输入账户名"""
        try:
            account = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div['
                                                         '4]/div/div/div/form/div[1]/div/div[1]/div/input')
            account.send_keys(account_name)
        except Exception as e:
            message = '添加用户——输入账户名参数检查'
            LOG_ERROR("error: found add_user_send_name timeout")
            print(e)
            LOG_INFO(message)

    def add_user_permission_list(self):
        """添加用户弹窗——权限列表"""
        try:
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div['
                                               '4]/div/div/div/form/div[2]/div/div/div/div/div/input').click()
        except Exception as e:
            message = '弹窗——权限列表信息检查'
            LOG_ERROR("error: found add_user_permission_list timeout")
            print(e)
            LOG_INFO(message)

    def add_user_set_permission(self, permission="Reader"):
        """添加用户弹窗——设置用户权限"""
        try:
            if permission == "Reader":
                self.driver.find_element(By.XPATH, '/html/body/div[2]/div[last()]/div/div/div[1]/ul/li[2]/span').click()
            else:
                self.driver.find_element(By.XPATH, '/html/body/div[2]/div[last()]/div/div/div[1]/ul/li[1]/span').click()
        except Exception as e:
            message = '添加用户弹窗——设置用户权限检查'
            LOG_ERROR("error: found add_user_set_permission timeout")
            print(e)
            LOG_INFO(message)

    def pipeline_detail_button(self):
        """构建详情按钮"""
        try:
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[1]/div[1]').click()
        except Exception as e:
            message = '构建系统页面信息检查'
            LOG_ERROR("error: found pipeline_detail_button timeout")
            print(e)
            LOG_INFO(message)

    def alert_confirm(self):
        """弹窗确认按钮"""
        try:
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div['
                                               '3]/div/div/footer/div/span/button[1]/span').click()
        except Exception as e:
            message = '弹窗确认按钮定位失败'
            LOG_ERROR("error: found alert_confirm timeout")
            print(e)
            LOG_INFO(message)

    def alert_cancel(self):
        """弹窗取消按钮"""
        try:
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div['
                                               '3]/div/div/footer/div/span/button[2]').click()
        except Exception as e:
            message = '弹窗取消按钮定位失败'
            LOG_ERROR("error: found alert_cancel timeout")
            print(e)
            LOG_INFO(message)

    def alert_message(self):
        """
        获取弹窗元素
        """
        mouse_alert = self.driver.find_element(By.XPATH, '/html/body/div[3]')
        ActionChains(self.driver).move_to_element(mouse_alert).perform()
        alert = self.driver.find_element(By.XPATH, '/html/body/div[3]')

        return alert.text

    def driver_refresh(self):
        """
        刷新页面
        """
        try:
            self.driver.refresh()
        except Exception as e:
            message = '刷新页面失败'
            LOG_ERROR("error: found driver_refresh timeout")
            print(e)
            LOG_INFO(message)

    def pipeline_add_user(self, account_name, permission):
        """用户管理页面添加用户"""
        self.account_manager_button()
        time.sleep(1)
        self.add_user_btn()
        time.sleep(2)
        self.add_user_send_name(account_name=account_name)
        time.sleep(1)
        self.add_user_permission_list()
        time.sleep(3)
        self.add_user_set_permission(permission=permission)
        time.sleep(3)
        self.add_user_confirm_btn()

    def pipeline_add_user_delete(self, user_name="owner"):
        """
        用户管理页面——删除用户
        """
        try:
            if user_name == "owner":
                self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div[2]/div/div['
                                                   '1]/div[3]/div/div[1]/div/table/tbody/tr/td['
                                                   '3]/div/button/span').click()
            else:
                self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div[2]/div/div['
                                                   '1]/div[3]/div/div[1]/div/table/tbody/tr[last()]/td['
                                                   '3]/div/button/span').click()
        except Exception as e:
            message = '删除用户失败'
            LOG_ERROR("error: found pipeline_add_user_delete timeout")
            print(e)
            LOG_INFO(message)

    def delete_user_confirm_btn(self):
        """
        删除用户弹窗——确认按钮
        """
        try:
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div['
                                               '5]/div/div/footer/span/button[1]/span').click()
        except Exception as e:
            message = '删除用户弹窗——确认按钮定位失败'
            LOG_ERROR("error: found delete_user_confirm_btn timeout")
            print(e)
            LOG_INFO(message)

    def delete_user_cancel_btn(self):
        """
        删除用户弹窗——取消按钮
        """
        try:
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div['
                                               '5]/div/div/footer/span/button[2]/span').click()
        except Exception as e:
            message = '删除用删除用户弹窗——取消按钮定位失败'
            LOG_ERROR("error: found delete_user_cancel_btn timeout")
            print(e)
            LOG_INFO(message)

    def change_user_permission_btn(self, user_name="owner"):
        """
        用户管理页面——更改角色权限按钮
        """
        try:
            if user_name == "owner":
                self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div[2]/div/div['
                                                   '1]/div[3]/div/div[1]/div/table/tbody/tr/td['
                                                   '2]/div/div/div/div/div/div/input').click()
            else:
                self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div/div[2]/div/div['
                                                   '1]/div[3]/div/div[1]/div/table/tbody/tr[last()]/td['
                                                   '2]/div/div/div/div/div/div/span/span/i/svg').click()
        except Exception as e:
            message = '用户管理页面——更改角色权限按钮'
            LOG_ERROR("error: found change_owner_permission_btn timeout")
            print(e)
            LOG_INFO(message)

    def change_permission(self, user_name="owner", permission="Maintainer"):
        """
        用户管理页面——修改已有用户权限
        """
        try:
            if user_name == "owner":
                if permission == "Maintainer":
                    self.driver.find_element(By.XPATH, '/html/body/div[2]/div[4]/div/div/div[1]/ul/li[1]/span').click()
                else:
                    self.driver.find_element(By.XPATH, '/html/body/div[2]/div[4]/div/div/div[1]/ul/li[2]/span').click()
            else:
                if permission == "Maintainer":
                    self.driver.find_element(By.XPATH, '/html/body/div[2]/div[6]/div/div/div[1]/ul/li[1]/span').click()
                else:
                    self.driver.find_element(By.XPATH, '/html/body/div[2]/div[6]/div/div/div[1]/ul/li[2]/span').click()
        except Exception as e:
            message = '用户管理页面——修改已有用户权限'
            LOG_ERROR("error: found change_permission timeout")
            print(e)
            LOG_INFO(message)

    def image_build_custom_service_button(self):
        """镜像定制——定制业务包按钮"""
        try:
            self.driver.find_element(By.XPATH,
                                     '/html/body/div[1]/div[1]/div/div[2]/div/div[2]/section/section/aside/div['
                                     '3]/div[2]/div[1]').click()
        except Exception as e:
            message = '镜像定制——定制业务包按钮元素定位失败'
            LOG_ERROR("error: found custom_service_button timeout")
            print(e)
            LOG_INFO(message)

    def image_build_param_change_button(self):
        """镜像定制——参数修改按钮"""
        try:
            self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div/div['
                                               '2]/section/section/main/div[1]/div/div/div[1]/button').click()
        except AttributeError as e:
            message = '镜像定制——按钮元素定位失败'
            LOG_ERROR("error: found custom_service_button timeout")
            print(e)
            LOG_INFO(message)

    def image_build_param_title(self):
        """镜像定制——参数页面标题"""
        try:
            info_title = self.driver.find_element(By.XPATH, '//*[@id="right"]/div[1]/div/div/div[1]/div')

            return info_title.text
        except AttributeError as e:
            message = '镜像定制——按钮元素定位失败'
            LOG_ERROR("error: found custom_service_button timeout")
            print(e)
            LOG_INFO(message)

    def image_build_start_title(self):
        """镜像定制——开始页面标题"""
        try:
            info_title = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/p')
            return info_title.text
        except AttributeError as e:
            message = '镜像定制——开始页面信息定位失败'
            LOG_ERROR("error: found image_build_start_title timeout")
            print(e)
            LOG_INFO(message)

    def image_build_config_cancel_button(self):
        """镜像定制——定制业务包参数配置取消按钮"""
        try:
            self.driver.find_element(By.XPATH, '//*[@id="right"]/div[1]/div/div/div/div[2]/button[2]/span').click()
        except AttributeError as e:
            message = '镜像定制——定制业务包参数配置取消按钮定位失败'
            LOG_ERROR("error: found image_build_config_cancel_button timeout")
            print(e)
            LOG_INFO(message)

    def image_build_config_save_button(self):
        """镜像定制——定制业务包参数配置保存按钮"""
        try:
            self.driver.find_element(By.XPATH, '//*[@id="right"]/div[1]/div/div/div/div[2]/button[1]/span').click()
        except AttributeError as e:
            message = '镜像定制——定制业务包参数配保存按钮定位失败'
            LOG_ERROR("error: found image_build_config_save_button timeout")
            print(e)
            LOG_INFO(message)

    def image_build_config_fill_check(self):
        """镜像定制——定制业务包参数必填校验"""
        try:
            fill_info_1 = self.driver.find_element(By.XPATH, '//*[@id="right"]/div[1]/div/div/form/div[1]/div['
                                                             '1]/div/div[2]')
            fill_info_2 = self.driver.find_element(By.XPATH, '//*[@id="right"]/div[1]/div/div/form/div[1]/div['
                                                             '3]/div/div[2]')
            fill_info_3 = self.driver.find_element(By.XPATH, '//*[@id="right"]/div[1]/div/div/form/div[3]/div/div[2]')

            return [fill_info_1.text, fill_info_2.text, fill_info_3.text]
        except AttributeError as e:
            message = '镜像定制——定制业务包参数必填信息定位失败'
            LOG_ERROR("error: found image_build_config_save_button timeout")
            print(e)
            LOG_INFO(message)

    def image_build_os_name(self):
        """镜像定制——产品名称输入框元素定位"""
        try:
            self.os_name_ib = self.driver.find_element(By.XPATH, '//*[@id="right"]/div[1]/div/div/form/div[1]/div['
                                                                 '1]/div/div/div/input')
        except AttributeError as e:
            message = '镜像定制——产品名称输入框元素定位失败'
            LOG_ERROR("error: found image_build_os_name timeout")
            print(e)
            LOG_INFO(message)

    def image_build_kernel_param(self):
        """镜像定制————内核参数输入框元素定位"""
        try:
            self.kernel_param = self.driver.find_element(By.XPATH, '//*[@id="right"]/div[1]/div/div/form/div[1]/div['
                                                                   '3]/div/div[1]/div/textarea')
        except AttributeError as e:
            message = '镜像定制——内核参数输入框元素定位失败'
            LOG_ERROR("error: found image_build_kernel_param timeout")
            print(e)
            LOG_INFO(message)

    def image_build_repo_url(self):
        """镜像定制——repo源地址输入框"""
        try:
            self.repo_url_ib = self.driver.find_element(By.XPATH, '//*[@id="right"]/div[1]/div/div/form/div['
                                                                  '3]/div/div[1]/div/textarea')
        except AttributeError as e:
            message = '镜像定制——repo源地址输入框元素定位失败'
            LOG_ERROR("error: found image_build_repo_url timeout")
            print(e)
            LOG_INFO(message)

    def image_build_send_keys_custom(self, os_name, kernel_param, repo_url):
        """镜像定制——定制业务包参数输入值"""
        self.os_name_ib.send_keys(os_name)
        self.kernel_param.send_keys(kernel_param)
        self.repo_url_ib.send_keys(repo_url)

    def image_build_get_value(self):
        """镜像定制——获取定制业务包参数值"""
        try:
            info_1 = self.driver.find_element(By.XPATH, '//*[@id="right"]/div[1]/div/div/div[2]/div[1]/div[2]')
            info_2 = self.driver.find_element(By.XPATH, '//*[@id="right"]/div[1]/div/div/div[2]/div[3]/div[2]')
            info_3 = self.driver.find_element(By.XPATH, '//*[@id="right"]/div[1]/div/div/div[4]/div[2]/p')

            return [info_1.text, info_2.text, info_3.text]
        except Exception as e:
            message = '镜像定制——repo源地址输入框元素定位失败'
            LOG_ERROR("error: found image_build_repo_url timeout")
            print(e)
            LOG_INFO(message)

    def add_pipeline_image_build(self, image_type, pipeline_group, pipeline_name, image_format, arch, flag=False,
                                 image_scene=None):
        """
        添加流水线
        """
        image_page = ImageBuild(self.driver)
        info = image_page.add_pipeline_image_build(image_type, pipeline_group, pipeline_name, image_format, arch)

        return info

    def div_cancel(self):
        """
        流水线弹窗取消按钮
        """
        image_page = ImageBuild(self.driver)
        image_page.div_cancel()

    def os_name_valid_check(self):
        """
        参数校验——os名称总长度校验
        """
        try:
            valid_info = self.driver.find_element(By.XPATH, '//*[@id="right"]/div/div[2]/form/div[4]')
            return valid_info.text
        except Exception as e:
            message = '参数校验——os名称总长度校验元素定位失败'
            LOG_ERROR("error: found os_name_valid_check timeout")
            print(e)
            LOG_INFO(message)